package mate.task.odin;

import android.app.Activity;
import android.content.Intent;

import com.google.android.maps.MapActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

public class ToDoItemActivity extends Activity{
	
	private TextView name, description, tags, date, location;
	private Button map, delete;
	private ToDoItem item;
	
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);

		setContentView(R.layout.todoitem);
		
		Bundle b = getIntent().getExtras();
		item = (ToDoItem) b.getSerializable("item");
		
		name = (TextView) findViewById(R.id.itemName);
		description = (TextView) findViewById(R.id.itemDescription);
		tags = (TextView) findViewById(R.id.itemTags);
		date = (TextView) findViewById(R.id.itemDate);
		location = (TextView) findViewById(R.id.itemLocation);
		map = (Button) findViewById(R.id.LocateButton);
		delete = (Button) findViewById(R.id.delete);
		
		name.setText("Name: " + item.getName());
		description.setText("Description: " + item.getDescription());
		tags.setText("Tags: " + item.getTags());
		date.setText("Date: " + item.getDate().toString());
		location.setText("Location: " + item.getLocation());
		
		//TODO: Implement map activity with click listener
		
		delete.setOnClickListener(new View.OnClickListener(){
			public void onClick(View v) {
				UserDatabase db = UserDatabase.getDatabaseInstance();
				ToDoList list = db.getCurrentUser().getList();
				list.deleteItem(item.getName());
				finish();
			}
		});
		map.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Bundle c = new Bundle();
				c.putSerializable("loc", item.getLocation());
				Intent g = new Intent("mate.task.odin.LOCATEACTIVITY");
				g.putExtras(c);
				startActivity(g);
			}
		});
	}
	public void onPause(){
		super.onPause();
		finish();
	}

}
